import urllib.request as r
import urllib.parse as p
import http.cookiejar as c
url='http://bbs.chinaunix.net/member.php?mod=logging&action=login&loginsubmit=yes&loginhash=LxogS'
postdata=p.urlencode({
    'username':'admintest166',
    'password':'test1234'

}).encode('utf-8')
req=r.Request(url,postdata)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36')
data=r.urlopen(req).read()
with open('1.html','wb')as f:
    f.write(data)
    print('1.html爬取完毕')

url2='http://bbs.chinaunix.net/'
req2=r.Request(url2,postdata)
req2.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36')
data2=r.urlopen(req2).read()
with open('2.html','wb')as l:
    l.write(data2)
    print('2.html爬取完毕')